package fitness

import (
	"fitness/internal/dao/fitness"
	fitnessEntity "fitness/internal/entity/fitness"
	"fitness/pkg/utils/R"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"net/http"
)

type UserService struct {
	UserDao *fitness.UserDao
	Log     *zap.Logger
}

func NewUserService(UserDao *fitness.UserDao,
	Log *zap.Logger) *UserService {
	return &UserService{
		UserDao: UserDao,
		Log:     Log,
	}
}

func (s *UserService) GetUserPage(c *gin.Context) {
	var pageQuery fitnessEntity.MpUserPageQuery
	err := c.ShouldBindQuery(&pageQuery)
	if err != nil {
		c.JSON(http.StatusOK, R.ReturnFailMsg(err.Error()))
		return
	}
	users, err := s.UserDao.GetUserPage(pageQuery)
	if err != nil {
		c.JSON(http.StatusOK, R.ReturnFailMsg(err.Error()))
		return
	}
	c.JSON(http.StatusOK, R.ReturnSuccess(users))
}
